package com.cloud.school.app.controller;

import com.cloud.school.app.config.security.SecurityUserUtils;
import com.cloud.school.app.model.CommentModel;
import com.cloud.school.app.model.LikeModel;
import com.cloud.school.app.model.ShowModel;
import com.cloud.school.app.service.CommentService;
import com.cloud.school.app.service.LikeService;
import com.cloud.school.app.service.ShowService;
import com.cloud.school.app.util.Pager;
import com.cloud.school.app.util.ResponseUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName ShowController
 * @Description TODO
 * @Author 36297
 * @Date 2018/12/17 21:47
 * @Version 1.0
 */
@Api(tags = "个人show控制器")
@RestController
@RequestMapping("/show")
public class ShowController {
    @Autowired
    private ShowService showService;
    @Autowired
    private CommentService commentService;
    @Autowired
    private LikeService likeService;

    @ApiOperation("分页查询所有动态")
    @RequestMapping(value = "/all", method = RequestMethod.GET)
    public ResponseUtil<Pager<ShowModel>> all(@ApiParam("页数") @RequestParam(defaultValue = "1") int pNo) {
        return ResponseUtil.ok(showService.selectAllDetail(pNo));
    }

    @ApiOperation("根据showId查询show详情")
    @RequestMapping(value = "/detail", method = RequestMethod.GET)
    public ResponseUtil<ShowModel> detail(@ApiParam("showId") @RequestParam Long showId) {
        return ResponseUtil.ok(showService.selectDetailById(showId));
    }

    @ApiOperation("分页查询个人动态")
    @RequestMapping(value = "/queryByUid", method = RequestMethod.GET)
    public ResponseUtil<Pager<ShowModel>> getByUid(@ApiParam("用户id") @RequestParam Long userId, @ApiParam("页数") @RequestParam(defaultValue = "1") int pNo) {
        return ResponseUtil.ok(showService.selectDetailByUid(userId, pNo));
    }

    @ApiOperation("分页查询所有动态(评论无层级关系)")
    @RequestMapping(value = "/allWithoutCommentFormat", method = RequestMethod.GET)
    public ResponseUtil<Pager<ShowModel>> allWithoutCommentFormat(@ApiParam("页数") @RequestParam(defaultValue = "1") int pNo) {
        return ResponseUtil.ok(showService.selectAllDetailWithoutCommentFormat(pNo));
    }

    @ApiOperation("根据showId查询show详情(评论无层级关系)")
    @RequestMapping(value = "/detailWithoutCommentFormat", method = RequestMethod.GET)
    public ResponseUtil<ShowModel> detailWithoutCommentFormat(@ApiParam("showId") @RequestParam Long showId) {
        return ResponseUtil.ok(showService.selectDetailWithoutCommentFormatById(showId));
    }

    @ApiOperation("分页查询个人动态(评论无层级关系)")
    @RequestMapping(value = "/queryWithoutCommentFormatByUid", method = RequestMethod.GET)
    public ResponseUtil<Pager<ShowModel>> queryWithoutCommentFormatByUid(@ApiParam("用户id") @RequestParam Long userId, @ApiParam("页数") @RequestParam(defaultValue = "1") int pNo) {
        return ResponseUtil.ok(showService.selectDetailWithoutCommentFormatByUid(userId, pNo));
    }

    @ApiOperation("新增个人动态")
    @RequestMapping(value = "/create", method = RequestMethod.POST)
    public ResponseUtil<Boolean> create(@RequestBody ShowModel showModel) {
        showModel.setCreateUid(SecurityUserUtils.getCurrentUserId());
        return ResponseUtil.ok(showService.save(showModel));
    }

    @ApiOperation("发表评论")
    @RequestMapping(value = "/comment", method = RequestMethod.POST)
    public ResponseUtil<Boolean> comment(@RequestBody CommentModel commentModel) {
        commentModel.setCreateUid(SecurityUserUtils.getCurrentUserId());
        return ResponseUtil.ok(commentService.save(commentModel));
    }

    @ApiOperation("点赞")
    @RequestMapping(value = "/like", method = RequestMethod.POST)
    public ResponseUtil<Boolean> like(@ApiParam("个人showId") @RequestParam Long showId) {
        LikeModel likeModel = new LikeModel();
        likeModel.setShowId(showId);
        likeModel.setCreateUid(SecurityUserUtils.getCurrentUserId());
        return ResponseUtil.ok(likeService.save(likeModel));
    }

    @ApiOperation("查询show赞记录")
    @RequestMapping(value = "/likeInfo", method = RequestMethod.GET)
    public ResponseUtil<List<LikeModel>> likeInfo(@ApiParam("个人showId") @RequestParam Long showId) {
        return ResponseUtil.ok(likeService.selectByShowId(showId));
    }

    @ApiOperation("删除show记录")
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public ResponseUtil<Boolean> deleteById(@ApiParam("个人showId") @RequestParam Long showId) {
        return ResponseUtil.ok(showService.deleteById(showId));
    }
}
